import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
import { HttpClient, HttpParams } from '@angular/common/http';
@Injectable({
  providedIn: 'root'
})
export class WorkShopService {

  constructor(private http:HttpClient) { }
  private WorkShop = '/WorkShop';
  private createPaginationParams(currentPage: number, itemsPerPage: number): HttpParams {
    return new HttpParams()
      .set('page', currentPage.toString())
      .set('pageSize', itemsPerPage.toString());
  }// 创建分页参数
  CreateWorkshop(data:any){
    return this.http.post(environment.apiUrl+ this.WorkShop+'/CreateWorkshop',data)
  }// 创建车间

  GetWorkshops(Status:any,SearchTerm?:any,page?: number, pageSize?: number){
    let params = new HttpParams();
    if (Status ) {
      params = params.set('Status', Status);
    }
    if (SearchTerm ) {
      params = params.set('WorkshopName', SearchTerm);
    }
    if (page !== undefined && pageSize !== undefined) {
      params = params.set('PageNumber', page.toString());
      params = params.set('PageSize', pageSize.toString());
    }
    return this.http.get(environment.apiUrl+ this.WorkShop+'/GetWorkshops',{
      params: params
    })
  }// 获取所有车间

  GetWorkshopById(id:any){
    return this.http.get(environment.apiUrl+ this.WorkShop+'/GetWorkshopById?id='+id)
  }// 获取车间

  DeleteWorkshop(id:any){
    return this.http.delete(environment.apiUrl+ this.WorkShop+'/DeleteWorkshop?id='+id)
  }// 删除车间

  UpdateWorkshop(data:any,id:any){
    return this.http.put(environment.apiUrl+ this.WorkShop+'/UpdateWorkshop',data,{params:{id:id}})
  }// 更新车间
  EnableWorkshops(ids:any){
    return this.http.post(environment.apiUrl+ this.WorkShop+'/EnableWorkshops',ids)
  }// 启用车间
  DisableWorkshops(ids:any){
    return this.http.post(environment.apiUrl+ this.WorkShop+'/DisableWorkshops',ids)
  }// 禁用车间
}
